package com.zhoudy.segmetqueue;

import com.zhoudy.segmetlock.SegmentDataWithLock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentLinkedQueue;

public class SegmentDataWithQueue {

    //数据段的队列
    private ConcurrentLinkedQueue<List<String>> dataQueue = new ConcurrentLinkedQueue<>();


    //分段大小
    private final int segmentSize = 8;


    /**
     * 对数组进行分段并存储到队列
     */
    public void blockFullWithSegmentation(String[] arr) {List<List<String>> segList = new ArrayList<>();
        List<String> srcList= Arrays.asList(arr);
        //开始分段
        SegmentDataWithLock.delivedEachSubList(srcList,segList,segmentSize);

        //为每个分段存储到队列
        for (int i = 0; i < segList.size(); i++) {
            //System.out.println(segList.get(i).toString()+"");
            List<String> singleSegList = segList.get(i);
            dataQueue.offer(singleSegList);
        }
    }

    public List<String> getNodeFromDataQueue() {
        return dataQueue.poll();
    }

    public boolean isEmptyQueue(){
        return  dataQueue.isEmpty();
    }
}
